<!-- 岗位操作指引弹窗 -->
<template>
  <a-modal v-model="visible" width="60%" title="岗位操作指引" cancelText="关闭" okText="提交" :keyboard="false" :maskClosable="false" @cancel="cancelFn" @ok="handleOk">
    <a-spin :spinning="loading">
      <a-form-model ref="ruleForm" :model="form" :rules="rules" :labelCol="{ lg: { span: 6 }, sm: { span: 6 } }" :wrapperCol="{ lg: { span: 18 }, sm: { span: 18 } }">
        <a-col>
          <a-form-model-item label="岗位名称" prop="postName">
            <BaseInput v-model="form.postName" disabled></BaseInput>
          </a-form-model-item>
        </a-col>
        <a-col>
          <a-form-model-item label="操作指引" prop="postManual">
            <editor-bar v-model="form.postManual" :isClear="isClear"></editor-bar>
          </a-form-model-item>
        </a-col>
        <a-col>
          <a-form-model-item label="附件上传">
            <upload-list :businessCode="'BM22'" :uploadArrys.sync="form.fileInfoList" @fileArrysData="handleFileUploaded" multiple></upload-list>
          </a-form-model-item>
        </a-col>
      </a-form-model>
    </a-spin>
  </a-modal>
</template>
<script>
import EditorBar from '@/components/Editor/editor'
import UploadList from '@/components/UploadList'
import { getAcloudPostManualByPostId, updateByPrimaryKeySelective } from '@/api/system/system'
export default {
  name: 'OperationGuideForm',
  components: {
    EditorBar,
    UploadList
  },
  props: {
    formData: {
      type: Object,
      default: () => {}
    }
  },
  data() {
    return {
      visible: true,
      loading: true,
      form: {
        fileInfoList: null,
        modifyTime: null,
        modifyUser: null,
        orgId: null,
        orgName: null,
        postCode: null,
        postId: null,
        postManual: null,
        postName: null,
        postTags: null
      },
      isClear: false,
      rules: {}
    }
  },
  created() {
    // 查询详情
    getAcloudPostManualByPostId({ postId: this.formData.postId }).then((res) => {
      if (res.code == '0' || res.code == '200') {
        this.form = res.data;
        this.loading = false;
      }else {
        this.loading = false;
        this.$message.error('详情查询失败');
      }
    })
  },
  methods: {
    // 附件上传回调
    handleFileUploaded(list) {
      this.form.fileInfoList = [...list]
    },

    // 提交函数回调
    handleOk(e) {
      // console.log('567890', this.form)
      updateByPrimaryKeySelective(this.form).then((res) => {
        if (res.code == '0' || res.code == '200') {
          this.$message.success('修改成功');
          this.$emit('click', { type: 'confirm' })  // 保存成功返回回调函数
        }else {
          this.$message.error('修改失败')
        }
      })
    },

    // 弹窗关闭，返回点击事件，父组件回调处理弹窗关闭及其他逻辑
    cancelFn() {
      this.$emit('click', { type: 'close' })
    }
  }
}
</script>

<style lang="less" scoped>
::v-deep {
  .ant-form-item .ant-form-item-label {
    width: 80px;
  }
}
</style>